﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Security.Cryptography;

namespace mbine.msgc.tool
{
    public static class StringExtentions
    {
        public static string Md5(this string s)
        {
            MD5 md5 = MD5.Create();
            byte[] inputBytes = System.Text.Encoding.ASCII.GetBytes(s);
            byte[] hashBytes = md5.ComputeHash(inputBytes);

            StringBuilder sb = new StringBuilder();
            for (int i = 0; i < hashBytes.Length; i++)
            {
                sb.Append(hashBytes[i].ToString("X2"));
            }
            return sb.ToString();
        }
        public static string CreateRandomPassword(int PasswordLength)
        {
            string allowedChars = "abcdefghijkmnopqrstuvwxyzABCDEFGH­ JKLMNOPQRSTUVWXYZ0123456789";
            Random rNum = new Random();
            string NewPassWord = "";
            for (int i = 0; i < PasswordLength; i++)
            {
                NewPassWord += allowedChars[rNum.Next(allowedChars.Length)];
            }
            return NewPassWord;
        }
    }
}
